import request from '@/utils/request'
import { obj2query } from '@/utils/tools'
import type { GoodsDetailData, GoodTableData } from '@/api/types/goods'
// 商品goods列表
export function reqGoodsList(page: number, query: {}) {
  const r = obj2query(query)
  return request<GoodTableData>({
    url: `/admin/goods/${page}${r}`,
    method: 'get'
  })
}

// 删除
export function reqDeleteGoods(ids: number | number[]) {
  ids = Array.isArray(ids) ? ids : [ids]
  return request({
    url: `/admin/goods/delete_all`,
    method: 'post',
    data: { ids }
  })
}

// 新增
export function reqAddGoods(data: any) {
  return request({
    url: '/admin/goods',
    method: 'post',
    data
  })
}

// 修改
export function reqUpdateGoods(id: number, data: any) {
  return request({
    url: `/admin/goods/${id}`,
    method: 'post',
    data
  })
}

// 修改状态 批量上架下架商品
export function reqUpdateGoodsStatus(ids: number | number[], status: number) {
  ids = Array.isArray(ids) ? ids : [ids]
  return request({
    url: `/admin/goods/changestatus`,
    method: 'post',
    data: {
      ids,
      status
    }
  })
}

// 审核商品 审核 1同意 2拒绝
export function reqAuditGoods(id: number, ischeck: number) {
  return request({
    url: `/admin/goods/${id}/check`,
    method: 'post',
    data: {
      ischeck
    }
  })
}
// 获取商品详情
export function reqGoodsDetail(id: number) {
  return request<GoodsDetailData>({
    url: `/admin/goods/read/${id}`,
    method: 'get'
  })
}
